<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $id
 * @property integer $role_id
 * @property integer $organization_id
 * @property string $username
 * @property string $mobile
 * @property string $nickname
 * @property string $email
 * @property string $avatar
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property integer $created_by
 * @property integer $created_at
 * @property integer $updated_by
 * @property integer $updated_at
 * @property integer $deleted_by
 * @property integer $deleted_at
 * @property integer $is_deleted
 * @property string $last_login_ip
 * @property integer $last_login_time
 * @property integer $status
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['role_id', 'organization_id', 'mobile'], 'required'],
            [['role_id', 'organization_id', 'created_by', 'created_at', 'updated_by', 'updated_at', 'deleted_by', 'deleted_at', 'is_deleted', 'last_login_time', 'status'], 'integer'],
            [['username', 'nickname'], 'string', 'max' => 50],
            [['mobile'], 'string', 'max' => 20],
            [['email'], 'string', 'max' => 200],
            [['avatar'], 'string', 'max' => 500],
            [['auth_key'], 'string', 'max' => 32],
            [['password_hash', 'password_reset_token'], 'string', 'max' => 64],
            [['last_login_ip'], 'string', 'max' => 40],
            [['organization_id'], 'exist', 'skipOnError' => true, 'targetClass' => Organization::className(), 'targetAttribute' => ['organization_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '用户序号',
            'role_id' => '角色',
            'organization_id' => 'Organization ID',
            'username' => '用户名',
            'mobile' => '手机',
            'nickname' => '昵称',
            'email' => '电子邮箱',
            'avatar' => '头像',
            'auth_key' => '验证密钥',
            'password_hash' => '密码哈希值',
            'password_reset_token' => '重置密码token',
            'created_by' => '创建人',
            'created_at' => '创建时间',
            'updated_by' => '最后更新人',
            'updated_at' => '最后更新时间',
            'deleted_by' => '删除人',
            'deleted_at' => '删除时间',
            'is_deleted' => '是否已删除',
            'last_login_ip' => '最后登录IP',
            'last_login_time' => '最后登录时间',
            'status' => '状态',
        ];
    }
}
